<template>
    <section id="case-page">
      <section class="case-title">
         <w-row>
             <w-cell :width="iconTitleWidth">
               <img src="../../../static/img/list.png"/>
             </w-cell>
             <w-cell>
               <h2>经典病例</h2>
             </w-cell>
         </w-row>
      </section>
      <section class="case-list" v-for="item in caseList" @click="toDetail(item.ID,item.Type)">
         <w-row>
           <w-cell :width="iconWidth" :iconAlign="iconAlign">
              <img class='left-banner' src='../../assets/img/case/left-banner.jpg'/>
           </w-cell>
           <w-cell style="margin-left: 0.3rem;">
             <w-row>
               <p class="des">{{item.Name}}-{{item.ZyNo}}-{{item.ActiveHos}}</p>
             </w-row>
             <w-row>
               <!-- <w-cell class="des1">
                {{item.Sex}},{{item.Age}}岁，诱导期内用药：挥发罐刻度={{item.Med_YDQ.split('&')[0]}},
                氧气流量={{item.Med_YDQ.split('&')[1]}},
                应用时间={{item.Med_YDQ.split('&')[2]}}
                  <span>{{item.WriteTime | changeDateFormat}}</span>
                </w-cell>-->
             </w-row>
           </w-cell>
         </w-row>
      </section>
      <section class="case-menu">
        <case-menu :tag="1"></case-menu>
      </section>
    </section>
</template>

<script>
import Vue from 'vue'
import caseMenu from '../../components/caseMenu';
import { mapGetters, mapActions } from 'vuex';
import axios from 'axios'

export default {
    data() {
        return {
            iconWidth: 20,
            iconTitleWidth: 30,
            iconAlign: 'center'
        }
    },
    filters: {  
      changeDateFormat: function (val) {  
          if (val != null) {
            var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
            //月份为0-11，所以+1，月份小于10时补个0
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            return date.getFullYear() + "-" + month + "-" + currentDate;
          }
            return "";
      }
    }, 
    components: {
        caseMenu
    },
    computed: {
        ...mapGetters({
            caseList: 'caseList'
        })
    },
    mounted() {
            // if(localStorage.openID == "" || localStorage.openID == undefined || localStorage.openID == "undefined") {
            //      axios.get('/wx/getcodeurl', {　
            //         params: { 'Appid': 'wx27a54ca734af2cf8','redirect_uri': 'http://zqdn.aegis-s.com/wx/getwxusertocase' }
            //           }).then(function(response) {
            //             //引导用户根据地址获取code
            //             let wxobj = this.GetRequest(response.data);
            //             let openid = wxobj["/case?openid"];
            //             localStorage.openID = openid;
            //           }).catch(function(error) {　　
            //             console.log(error);　
            //     });
            // } else {
                // let openid = localStorage.openID;
                // this.checkUserInfo(openid).then((response)=> {
                // let _res = response[0];
                // if(_res.msg == '0') { 
                //     Wui.Toast.show('尚未注册，请先注册', 'middle');
                //     setTimeout(function() {
                //         location.href = '#/regist';
                //     }, 1000);
                // } else if(_res.msg == '1') {
                //     //纪录用户信息
                //     var _user = JSON.stringify(_res.userInfo);
                //     localStorage.setItem('userMsg', _res.userInfo3);
                //     this.getCaseList(this.$router.history.current.params.tid || 0);

                // } else {
                //      Wui.Toast.show(_res.msg, 'middle');
                // }
            //});
        //}
        this.getCaseList(this.$router.history.current.params.title || "");
    },
    methods: {
        ...mapActions([
            'getCaseList',
            'checkUserInfo'
        ]),
        toDetail: function(id,type) {
            if(type == 0) {
              this.$router.push({name:'caseDetail',params: {id: id}});
            } else {
                this.$router.push({name:'caseReportDetail',params: {id: id}});
            }
        },
        GetRequest: function(url) {
            var url = decodeURI(url); //获取url中"?"符后的字串   
            var theRequest = {};
            if (url.indexOf("?") != -1) {   
                var str = url.substr(1);   
                let strs = str.split("&");   
                for(var i = 0; i < strs.length; i ++) {   
                    theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);   
                }   
            }  
            return theRequest;   
        }
    }

}
//  window.addEventListener("popstate", function(e) {  //回调函数中实现需要的功能
//         Vue.prototype.$wx.closeWindow();
//  }, false);  
</script>

<style lang="scss" scoped>
   #case-page {
       font-size: 0.5rem !important;
       padding-bottom: 6rem;
       .case-title {
           background: #f2f2f2;
           padding: 0 0.5rem;
           img {
             width: 1rem;
           }
           h2 {
               color: #005ba8;
               font-weight: bold;
           }
       }
       .case-title > div {
           height: 1.8rem;
       }
       .case-list {
           width: 95%;
           margin: 0 auto;
           padding: 0.5rem 0;
           border-bottom: 1px solid #e7e7e7;
           .left-banner {
               width: 4.725rem;
               height: 3.225rem;
           }
           .des {
               margin: 0 0 0.35rem 0;
           }
           .des1 {
              font-size: 0.5rem;
           }
           .des1 {
               color: #d4d4d4;
               display: inline-block;
           }
           .des1 span {
               margin-left: 6px;
               float: right;
           }
       }
   }
</style>